package pers.li.controller.address;

import pers.li.service.AddressService;
import pers.li.utils.PublicUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/setDefaultAddress")
public class SetDefaultAddress extends HttpServlet {
    private final AddressService addressService = new AddressService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int addressId = Integer.parseInt(req.getParameter("addressId"));
        Integer userId = PublicUtils.getLoginUserId(req);
        addressService.setDefault(userId, addressId);
        resp.sendRedirect("addressCenter.action");
    }
}
